/* 
 * File:   ContadorDeIntensidade.cpp
 * Author: guilhermemg
 * 
 * Created on 7 de Outubro de 2011, 11:52
 */

#include "AveragePixelSaturation.h"
#include "algorithm/Algorithm.h"

AveragePixelSaturation::AveragePixelSaturation() : Average() {
    setName("f3");
    setLargeName("f3 - averagePixelSaturation");
}

AveragePixelSaturation::AveragePixelSaturation(const AveragePixelSaturation& orig) : Average(orig) {
}

AveragePixelSaturation::~AveragePixelSaturation() {
}
    
void AveragePixelSaturation::calculates() {
    double sum = 0;
    
    for(int i = 0; i < this->getImage()->height; i++) {
        uchar* ptr = (uchar*)(this->getImage()->imageData + i*this->getImage()->widthStep);
        for(int j = 0; j < this->getImage()->width; j++) {
            sum += ptr[3*j + 1];
        }
    }
    
    sum = (sum/255)*100;
    // faz a media aritmetica para a imagem toda
    setValue(sum/(double)(this->getImage()->height * this->getImage()->width));
}


